package cn.hwadee.muying.service;

import cn.hwadee.muying.entity.Reception;
import cn.hwadee.muying.mapper.ReceptionMapper;
import cn.hwadee.muying.commons.base.BaseService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.stereotype.Service;
import cn.hwadee.muying.entity.User;
import cn.hwadee.muying.commons.page.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * <p>
 * 接待情况 服务实现类
 * </p>
 *
 * @author Mankind
 * @since 2018-08-06
 */
@Service
public class ReceptionService extends BaseService<ReceptionMapper, Reception> {

    @Autowired
    private ReceptionMapper receptionMapper;
    @Autowired
    private UserService userService;


    public MyPage<Reception> list(MyPage<Reception> page, User cUser,Integer status) throws Exception{
        List<Reception> receptions = receptionMapper.list(page,cUser,status);

        for(Reception reception:receptions){
            Long followerId=reception.getFollowerId();
            if(followerId!=null){
                User user=userService.selectById(followerId);
                reception.setUserName(user.getUsername());
            }
        }
        page.setRecords(receptions);
        return page;
    }


    public List<Reception> selectFollowedClient(User cUser){
        return receptionMapper.selectFollowedClient(cUser);
    }

    public Reception selectByAccount(String account) {
        List<Reception> receptionList=receptionMapper.selectList(
                new EntityWrapper<Reception>()
                            .and("telephone="+account)
                            .and("valid=1")
        );
        if(receptionList.size()>0){
            return receptionList.get(0);
        }else{
            return null;
        }
    }
}
